//
// Created by Tan Ke on 2024/1/12.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>


struct RecordItem
{
    char* word;
    int len;
    int words1Cnt;
    int words2Cnt;
};

int countWords(char** words1, int words1Size, char** words2, int words2Size)
{
    struct RecordItem* recordMap = (struct RecordItem*)malloc(sizeof(struct RecordItem) * (words1Size + words2Size));
    int recordMapLen = 0;
    int result = 0;
    memset(recordMap, 0, sizeof(struct RecordItem) * (words1Size + words2Size));

    for (int i = 0; i < words1Size; i ++) {
        bool found = false;
        for (int m = 0; m < recordMapLen; m ++) {
            if (recordMap[m].len == strlen(words1[i]) && strcmp(recordMap[m].word, words1[i]) == 0) {
                recordMap[m].words1Cnt += 1;
                found = true;
                break;
            }
        }
        if (found == false) {
            recordMap[recordMapLen].word = (char*)malloc(sizeof(char) * (strlen(words1[i]) + 1));
            memset(recordMap[recordMapLen].word, 0, (strlen(words1[i]) + 1));
            strcpy(recordMap[recordMapLen].word, words1[i]);
            recordMap[recordMapLen].len = strlen(words1[i]);
            recordMap[recordMapLen].words1Cnt += 1;
            recordMapLen += 1;
        }
    }

    for (int i = 0; i < words2Size; i ++) {
        bool found = false;
        for (int m = 0; m < recordMapLen; m ++) {
            if (recordMap[m].len == strlen(words2[i]) && strcmp(recordMap[m].word, words2[i]) == 0) {
                recordMap[m].words2Cnt += 1;
                found = true;
                break;
            }
        }
        if (found == false) {
            recordMap[recordMapLen].word = (char*)malloc(sizeof(char) * (strlen(words2[i]) + 1));
            memset(recordMap[recordMapLen].word, 0, (strlen(words2[i]) + 1));
            strcpy(recordMap[recordMapLen].word, words2[i]);
            recordMap[recordMapLen].len = strlen(words2[i]);
            recordMap[recordMapLen].words2Cnt += 1;
            recordMapLen += 1;
        }
    }

    for (int i = 0; i < recordMapLen; i ++) {
        if (recordMap[i].words1Cnt == 1 && recordMap[i].words2Cnt == 1) {
            result += 1;
        }
    }

    return result;
}

int main(void)
{
    return 0;
}
